package group.sicher.lock.brain;

import group.sicher.lock.constant.MarsLockConstant;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @description:
 * @author: aron
 * @date: 2019-08-05 15:46
 */
public class MarsLockKey {

    private List<String> keyList = new ArrayList<>();
    private long leaseTime = -1;
    private long waitTime = -1;
    private TimeUnit timeUnit = TimeUnit.SECONDS;

    private MarsLockKey(List<String> keyList, long leaseTime, long waitTime, TimeUnit timeUnit) {
        this.keyList = keyList;
        this.leaseTime = leaseTime;
        this.waitTime = waitTime;
        this.timeUnit = timeUnit;
    }

    public List<String> getKeyList() {
        return keyList;
    }

    public long getLeaseTime() {
        return leaseTime;
    }

    public long getWaitTime() {
        return waitTime;
    }

    public TimeUnit getTimeUnit() {
        return timeUnit;
    }

    public static Builder instance() {
        return new Builder();
    }

    public static class Builder {
        private List<String> keyList = new ArrayList<>();
        private long leaseTime = -1;
        private long waitTime = -1;
        private TimeUnit timeUnit = TimeUnit.SECONDS;

        public Builder setKey(String key) {
            keyList.add(MarsLockConstant.KEY_PREFIX + key);
            return this;
        }

        public Builder setLeaseTime(long leaseTime) {
            this.leaseTime = leaseTime;
            return this;
        }

        public Builder setWaitTime(long waitTime) {
            this.waitTime = waitTime;
            return this;
        }

        public Builder setTimeUnit(TimeUnit timeUnit) {
            this.timeUnit = timeUnit;
            return this;
        }

        public MarsLockKey build() {
            return new MarsLockKey(keyList,leaseTime,waitTime,timeUnit);
        }
    }
}
